#region Copyright
/*
Copyright Notice: 
Use of this file, in source or binary form, is subject to the terms and conditions set forth 
in the included license.txt file.
*/
#endregion

/* This is a customised template.
 * It overrides some optional methods from EntityMap to allow for testing 
 * with Mocks and fast object creation. Search for #custom# below. 
 */


namespace WebbnessCMS.Security.Models
{

	#region Using statements

	using System;
	using System.Collections;
	using System.Collections.Generic;
	using System.Data;
	using Neo.Core;
	using Expergent;
	using Expergent.Neo;
	using Castle.Components.Validator;
		using Neo.Core.Util;
		using Neo.Framework;
			
	#endregion

	#region IEntityMenuType

	/// <summary>
	/// Generated table specific Interface </summary>
	/// <remarks> This Interface is generated by the Neo Framework. Make changes to NeoSupport.vtl.</remarks>
	public partial interface IEntityMenuType
	{
			/// <summary>
		/// A collection of EntityType objects referencing this instance.</summary>
		/// <remarks> Objects referencing this instance.</remarks>
		ObjectRelation<EntityType> EntityType { get; }

			
				/// <summary>
		/// Property EntityMenuTypeID - No Description </summary>
		/// <remarks> Database Path: WebbnessCMS.Security_EntityMenuTypes.EntityMenuTypeID.</remarks>
		/// <value> System.Int32. </value>
			System.Int32? EntityMenuTypeID {get; set;}
	
					/// <summary>
		/// Property Name - No Description </summary>
		/// <remarks> Database Path: WebbnessCMS.Security_EntityMenuTypes.Name.</remarks>
		/// <value> System.String. </value>
			System.String Name {get; set;}
	
					/// <summary>
		/// Property Controller - No Description </summary>
		/// <remarks> Database Path: WebbnessCMS.Security_EntityMenuTypes.Controller.</remarks>
		/// <value> System.String. </value>
			System.String Controller {get; set;}
	
					/// <summary>
		/// Property ShowInMenu - No Description </summary>
		/// <remarks> Database Path: WebbnessCMS.Security_EntityMenuTypes.ShowInMenu.</remarks>
		/// <value> System.Boolean. </value>
			System.Boolean? ShowInMenu {get; set;}
	
		
		}

	#endregion

	#region EntityMenuType

	/// <summary>
	/// Generated table specific Base Class </summary>
	/// <remarks> This class is generated by the Neo Framework. Make changes to NeoSupport.vtl.</remarks>
	[Serializable]
	public partial class EntityMenuType : RulesEnabledEntityObject, IEntityMenuType
	{
			/// <summary>
		/// A collection of EntityType objects referencing this instance.</summary>
		/// <remarks> Objects referencing this instance.</remarks>
		public ObjectRelation<EntityType> EntityType
		{
			get {return _EntityType;}
		}
		
		private ObjectRelation<EntityType> _EntityType;
		
	
			internal EntityMenuType(System.Data.DataRow aRow, Neo.Core.ObjectContext aContext) : base(aRow, aContext)
		{
				_EntityType = new ObjectRelation<EntityType>(this, "EntityType");
				}
		
				/// <summary>
		/// Property EntityMenuTypeID - No Description </summary>
		/// <remarks> Database Path: WebbnessCMS.Security_EntityMenuTypes.EntityMenuTypeID.</remarks>
		/// <value> System.Int32. </value>
				public virtual System.Int32? EntityMenuTypeID
		{
			get { object v = Row["EntityMenuTypeID"]; return (System.Int32?)((v != DBNull.Value) ? v : null); }
				set { if (value.HasValue) Row["EntityMenuTypeID"] = value; else Row["EntityMenuTypeID"] = DBNull.Value; }
				}    

					/// <summary>
		/// Property Name - No Description </summary>
		/// <remarks> Database Path: WebbnessCMS.Security_EntityMenuTypes.Name.</remarks>
		/// <value> System.String. </value>
			[ValidateNonEmpty("Name is a required field.")]
				public virtual System.String Name
		{
			get { return Row["Name"] as System.String; }
				set { Row["Name"] = (value != null) ? (object)value : (object)DBNull.Value; }
				}    

					/// <summary>
		/// Property Controller - No Description </summary>
		/// <remarks> Database Path: WebbnessCMS.Security_EntityMenuTypes.Controller.</remarks>
		/// <value> System.String. </value>
				public virtual System.String Controller
		{
			get { return Row["Controller"] as System.String; }
				set { Row["Controller"] = (value != null) ? (object)value : (object)DBNull.Value; }
				}    

					/// <summary>
		/// Property ShowInMenu - No Description </summary>
		/// <remarks> Database Path: WebbnessCMS.Security_EntityMenuTypes.ShowInMenu.</remarks>
		/// <value> System.Boolean. </value>
			[ValidateNonEmpty("Show In Menu is a required field.")]
				public virtual System.Boolean? ShowInMenu
		{
			get { object v = Row["ShowInMenu"]; return (System.Boolean?)((v != DBNull.Value) ? v : null); }
				set { if (value.HasValue) Row["ShowInMenu"] = value; else Row["ShowInMenu"] = DBNull.Value; }
				}    

		
				/// <summary>
		/// Returns the value associated with the propName parameter.</summary>
		/// <remarks> You will need to cast the returned object into its native type upon return.</remarks>
		/// <param name="propName">String property name.</param>
		/// <returns> System.Object. </returns>
		public override object GetProperty(string propName)
		{
					if(propName == "EntityMenuTypeID") 
				return EntityMenuTypeID;
						if(propName == "Name") 
				return Name;
						if(propName == "Controller") 
				return Controller;
						if(propName == "ShowInMenu") 
				return ShowInMenu;
							if(propName == "EntityType") 
				return EntityType;
				return ExtendGetProperty(propName);
		}
		
		/// <summary>
		/// Sets the value associated with the propName parameter to the value specified.
		/// </summary>
		/// <param name="propName">String property name.</param>
		/// <param name="value">The value.</param>
		public override void SetProperty(string propName, object value)
		{
						if(propName == "EntityMenuTypeID") 
			{
				EntityMenuTypeID = (System.Int32?)value;
				return;
			}
								if(propName == "Name") 
			{
				Name = (System.String)value;
				return;
			}
								if(propName == "Controller") 
			{
				Controller = (System.String)value;
				return;
			}
								if(propName == "ShowInMenu") 
			{
				ShowInMenu = (System.Boolean?)value;
				return;
			}
							ExtendSetProperty(propName, value);
		}
		
		/// <summary>
		/// Adds a set of facts for this instance to the list.
		/// </summary>
		/// <param name="list">The list.</param>
		/// <param name="parent">The parent.</param>
		protected override void MakeFacts(List<WME> list, string parent)
		{
					list.Add(new WME(new EntityObjectTerm(this), MakePredicate(parent, "EntityMenuTypeID"), EntityMenuTypeID));
						list.Add(new WME(new EntityObjectTerm(this), MakePredicate(parent, "Name"), Name));
						list.Add(new WME(new EntityObjectTerm(this), MakePredicate(parent, "Controller"), Controller));
						list.Add(new WME(new EntityObjectTerm(this), MakePredicate(parent, "ShowInMenu"), ShowInMenu));
							list.Add(new WME(new EntityObjectTerm(this), MakePredicate(parent, "EntityType"), EntityType));
				ExtendMakeFacts(list, parent);
			myFactsHaveBeenAsserted = true;
		}

		/// <summary>
		/// Gets the default sort order.
		/// </summary>
		/// <value>The sort order.</value>
		public static PropertyComparer DefaultSortOrder
		{
			get
			{
					return new PropertyComparer("Name", SortDirection.Ascending);
				}    
		}

			/// <summary>
		/// Ensures related tables are loaded into memory for a cascaded delete.</summary>
		/// <remarks> Deletes related tables entries when cascade is specified.</remarks>
		public override void Delete() 
		{
					EntityType.Touch();
			while (EntityType.Count > 0)
			{
				EntityType[0].Delete();
			}
					base.Delete();
		}
			
		/// <summary>
		/// Populates the EntityObject from the specified surrogate.
		/// </summary>
		/// <param name="surrogate">The surrogate.</param>
		public void Populate(EntityMenuTypeSurrogate surrogate)
		{
							Name = surrogate.Name;
						Controller = surrogate.Controller;
						ShowInMenu = surrogate.ShowInMenu;
				}
	}

	#endregion

	#region EntityMenuTypeTemplate

	/// <summary>
	/// Generated table specific Query Template Class </summary>
	/// <remarks> A Query Template for EntityMenuType operations. </remarks>
	public class EntityMenuTypeTemplate : QueryTemplate
	{

		/// <summary>
		/// Constructor </summary>
		/// <remarks> Public Constructor.</remarks>
		/// <param name="anEntityMap">IEntityMap instance.</param>
		public EntityMenuTypeTemplate(IEntityMap anEntityMap) : base(anEntityMap)
		{
		}
		
				/// <summary>
		/// Property EntityMenuTypeID - No Description </summary>
		/// <remarks> Database Path: WebbnessCMS.Security_EntityMenuTypes.EntityMenuTypeID.</remarks>
		/// <value> System.Int32. </value>
		public System.Int32 EntityMenuTypeID
		{
			get { return (System.Int32)QueryValues["EntityMenuTypeID"]; }
			set { QueryValues["EntityMenuTypeID"] = value; }
		}

					/// <summary>
		/// Property Name - No Description </summary>
		/// <remarks> Database Path: WebbnessCMS.Security_EntityMenuTypes.Name.</remarks>
		/// <value> System.String. </value>
		public System.String Name
		{
			get { return (System.String)QueryValues["Name"]; }
			set { QueryValues["Name"] = value; }
		}

					/// <summary>
		/// Property Controller - No Description </summary>
		/// <remarks> Database Path: WebbnessCMS.Security_EntityMenuTypes.Controller.</remarks>
		/// <value> System.String. </value>
		public System.String Controller
		{
			get { return (System.String)QueryValues["Controller"]; }
			set { QueryValues["Controller"] = value; }
		}

					/// <summary>
		/// Property ShowInMenu - No Description </summary>
		/// <remarks> Database Path: WebbnessCMS.Security_EntityMenuTypes.ShowInMenu.</remarks>
		/// <value> System.Boolean. </value>
		public System.Boolean ShowInMenu
		{
			get { return (System.Boolean)QueryValues["ShowInMenu"]; }
			set { QueryValues["ShowInMenu"] = value; }
		}

				               
	}

	#endregion

	#region EntityMenuTypeFactory

	/// <summary>
	/// Factory class for the creation of EntityMenuType objects.</summary>
	public class EntityMenuTypeFactory : Neo.Framework.GenericObjectFactory<EntityMenuType>
	{

		/// <summary>
		/// Constructor requiring an ObjectContext parameter.</summary>
		/// <remarks> Main entry point for the retrieval and creation of new EntityMenuType objects.</remarks>
		/// <param name="context">ObjectContext.</param>
		public EntityMenuTypeFactory(ObjectContext context) : base(context, typeof(EntityMenuType))
		{
		}

			/// <summary>
		/// Create new EntityMenuType object.</summary>
		/// <remarks>IdMethod = Guid, PrimaryKeyIsForeignKey = False, RelationshipSetsForColumns = 1.</remarks>
		/// <returns> EntityMenuType </returns>
		public EntityMenuType CreateObject()
		{
			return (EntityMenuType)base.CreateObject(null);
		}
		
	
		/// <summary>
		/// Find a specified EntityMenuType object.</summary>
		/// <remarks> Requires Primary Key values and/or parent object instances.</remarks>
			/// <param name="arg0">.</param>
			/// <returns> EntityMenuType </returns>
		public EntityMenuType FindObject(System.Int32 arg0)
		{
			return (EntityMenuType)base.FindObject(new object[] { arg0 } );
		}

		///<summary>
		///Find a specified EntityMenuType object.</summary>
		///<remarks> Requires Primary Key values and/or parent object instances.</remarks>
			///<param name="arg0">.</param>
			///<returns> EntityMenuType </returns>
		public EntityMenuType FindObjectByPK( System.Int32 arg0 )
		{
			return (EntityMenuType) base.FindObject( new object[] {  arg0 } );
		}
		
					
			///<summary>
		///Find a specified EntityMenuType object.</summary>
		///<remarks> Requires Primary Key values and/or parent object instances.</remarks>
			///<param name="arg0">.</param>
			///<returns> EntityMenuType </returns>
		public EntityMenuType FindObjectByPK( System.Int32? arg0 )
		{
			return (EntityMenuType) base.FindObject( new object[] {  arg0.Value } );
		}
			
		/// <summary>
		/// Return the correct Query Template for the EntityMenuType object.</summary>
		/// <remarks> A query template is used for creating SQL like queries, in a more OO fashion.</remarks>
		/// <returns> EntityMenuTypeTemplate </returns>
		public EntityMenuTypeTemplate GetQueryTemplate()
		{
			return new EntityMenuTypeTemplate(EntityMap);
		}
		
		/// <summary>
		/// SQL like query to find and return an object.</summary>
		/// <remarks> For example: ...FindFirst("TitleAuthors.(Title = {0} or Title.Publisher = {1})", title, publisher).</remarks>
		/// <param name="qualifierFormat">String.</param>
		/// <param name="parameters">params object[].</param>
		/// <returns> EntityMenuType. </returns>
		public override EntityMenuType FindFirst(string qualifierFormat, params object[] parameters)
		{
			ObjectList<EntityMenuType> results = FindWithLimit(1, qualifierFormat, parameters);
			return (results.Count > 0) ? results[0] : null;
		}

		/// <summary>
		/// SQL like query to find and return an object.</summary>
		/// <remarks> For example: ...FindFirst("TitleAuthors.(Title = {0} or Title.Publisher = {1})", title, publisher).</remarks>
		/// <param name="q">The Qualifier.</param>
		/// <returns>EntityMenuType</returns>
		public override EntityMenuType FindFirst(Qualifier q)
		{
			FetchSpecification f = new FetchSpecification(EntityMap, q, 1);
			ObjectList<EntityMenuType> result = Find(f);
			return result.Count > 0 ? result[0]: null;
		}
	}

	#endregion

	#region EntityMenuTypeEntityMap

	//  -------- Entity Map -----------------------------------------------------
	/// <summary>Creates the in memory version of the dataset for the EntityMenuType DOM.</summary>
	/// <remarks>Generated by Neo Framework.</remarks>
	internal class EntityMenuTypeMap : EntityMap
	{
		  /// <summary>Array of Primary Key column names.</summary>
		  /// <remarks>Primary Key columns.</remarks>
		private static readonly string[] pkcolumns = { "EntityMenuTypeID" };
		/// <summary>Array of Database column names.</summary>
		  /// <remarks>Database column names.</remarks>
		private static readonly string[] columns = { "EntityMenuTypeID", "Name", "Controller", "ShowInMenu" };
		/// <summary>Array of DOM object properties.</summary>
		  /// <remarks>DOM object properties.</remarks>
		private static readonly string[] attributes = { "EntityMenuTypeID", "Name", "Controller", "ShowInMenu" };
		/// <summary>Array of Related Object names.</summary>
		  /// <remarks>Related Object names.</remarks>
		private static readonly string[] relations = { "EntityType" };

		private Type concreteObjectType = typeof(EntityMenuType);

		  /// <summary>Property ObjectType.</summary>
		  /// <remarks>Returns the DOM's Type.</remarks>
		  /// <value>System.Type.</value>
		public override System.Type ObjectType
		{
			get { return typeof(EntityMenuType); }
		}
	    
		/// <summary>Property ObjectType.</summary>
		  /// <remarks>Returns the DOM's Type.</remarks>
		  /// <value>System.Type.</value>
		public override System.Type ConcreteObjectType
		{
			get { return concreteObjectType; }										 /* #custom# overridden */
			set { concreteObjectType = value; Factory.AddCustomType(value, this); }  /* #custom# overridden */
		}
	    
		/// <summary>Property TableName.</summary>
		  /// <remarks>Returns database table name.</remarks>
		  /// <value>string.</value>
		public override string TableName
		{
			get { return "Security_EntityMenuTypes"; }
		}
	    
		/// <summary>Property PrimaryKeyColumns.</summary>
		/// <remarks>Array of Primary Key column names.</remarks>
		/// <value>string[].</value>
		public override string[] PrimaryKeyColumns
		{
			get { return pkcolumns; }
		}

		/// <summary>Property Columns.</summary>
		/// <remarks>Array of Database column names.</remarks>
		/// <value>string[].</value>
		public override string[] Columns
		{
			get { return columns; }
		}

		/// <summary>Property Attributes.</summary>
		/// <remarks>Array of DOM object properties.</remarks>
		/// <value>string[].</value>
		public override string[] Attributes
		{
			get { return attributes; }
		}

		/// <summary>Property Relations.</summary>
		/// <remarks>Array of Related Object names.</remarks>
		/// <value>string[].</value>
		public override string[] Relations
		{
			get { return relations; }
		}

		/// <summary>Generates a Hashtable, keyed by Object Name, or information regarding related objects.</summary>
		/// <remarks>Related Objects.</remarks>
		/// <returns>IDictionary.</returns>
  		protected override IDictionary GetRelationInfos()
		{
    		IDictionary infos = new Hashtable(1);
	 	 			infos.Add("EntityType", new RelationInfo(Factory, typeof(EntityMenuType), typeof(EntityType), "EntityMenuTypeID", "EntityMenuTypeID"));
					return infos;    	
		}
	    
		/// <summary>Based upon the model specified Id Method, returns the proper PkInitializer.</summary>
		/// <remarks>The object used to create a new PK value.</remarks>
		/// <returns>IPkInitializer.</returns>
		public override IPkInitializer GetPkInitializer()
		{
				return new GuidPkInitializer();
			}
	    
		/// <summary>Creates a new instance of EntityMenuType.</summary>
		/// <remarks>Create new EntityMenuType.</remarks>
		/// <param name="row">DataRow.</param>
		/// <param name="context">ObjectContext.</param>
		/// <returns>IEntityObject.</returns>
		public override IEntityObject CreateInstance(DataRow row, ObjectContext context) /* #custom# overridden */
		{
			if(ConcreteObjectType != ObjectType)
				return base.CreateInstance(row, context);
			return new EntityMenuType(row, context);
		}
	    
		/// <summary>Generates the in memory dataset.</summary>
		/// <remarks>Called by the Factory object.</remarks>
		/// <param name="table">DataTable.</param>
		protected override void WriteBasicSchema(DataTable table)
		{
			DataColumn		c;
			
				c = table.Columns.Add("EntityMenuTypeID", typeof(System.Int32));
					c.Unique = true;
										c = table.Columns.Add("Name", typeof(System.String));
								c = table.Columns.Add("Controller", typeof(System.String));
					c.AllowDBNull = true;
							c = table.Columns.Add("ShowInMenu", typeof(System.Boolean));
							c.DefaultValue = Convert.ChangeType("false", typeof(System.Boolean));
							table.PrimaryKey = new DataColumn[] { table.Columns["EntityMenuTypeID"] };
		}
		
			/// <summary>Generates the dataset relationships.</summary>
		/// <remarks>Dataset Relationships.</remarks>
		/// <param name="table">DataTable.</param>
		protected override void WriteRelations(DataTable table)
		{
			DataRelation r;
			
		 			if(table.DataSet.Relations["Security_EntityMenuTypes*Security_EntityTypes.EntityMenuTypeID"] == null)
			{
				r = table.DataSet.Relations.Add("Security_EntityMenuTypes*Security_EntityTypes.EntityMenuTypeID", 
						table.DataSet.Tables["Security_EntityMenuTypes"].Columns["EntityMenuTypeID"],
						table.DataSet.Tables["Security_EntityTypes"].Columns["EntityMenuTypeID"]);
				r.ChildKeyConstraint.UpdateRule = Rule.None;
				r.ChildKeyConstraint.DeleteRule = Rule.Cascade;
			}
				}
		}

	#endregion

	#region EntityMenuTypeSurrogate

	/// <summary>Represents an entity object disconnected from the database.</summary>
	/// <remarks>
	///   <para>Database Path: WebbnessCMS.Security_EntityMenuTypes.</para>
	/// </remarks>
	public partial class EntityMenuTypeSurrogate : EntityObjectSurrogate, IEntityMenuType
	{
		/// <summary>Default constructor.</summary>
		public EntityMenuTypeSurrogate()
		{
												_showinmenu = (System.Boolean)System.Convert.ChangeType("false", typeof(System.Boolean));
						}
	    
	    
	    
		/// <summary>
		/// Initializes a new instance of the <see cref="EntityMenuTypeSurrogate"/> class.
		/// </summary>
		/// <param name="entity">The entity.</param>
		public EntityMenuTypeSurrogate(EntityMenuType entity)
		{
					EntityMenuTypeID = entity.EntityMenuTypeID;
						Name = entity.Name;
						Controller = entity.Controller;
						ShowInMenu = entity.ShowInMenu;
				}

		/// <summary>
		/// A collection of EntityType objects referencing this instance.</summary>
		/// <remarks> Objects referencing this instance.</remarks>
		public ObjectRelation<EntityType> EntityType
		{
			get {return _EntityType;}
			set {_EntityType = value;}
		}
		
		private ObjectRelation<EntityType> _EntityType;

	
	
		/// <summary>
		/// Updates the entity with the values contained within the surrogate.
		/// </summary>
		/// <param name="entity">The entity.</param>
		public void BindObjectInstance(EntityMenuType entity)
		{
							entity.Name = Name;
						entity.Controller = Controller;
						entity.ShowInMenu = ShowInMenu;
				}

					/// <summary>
		/// Property EntityMenuTypeID - No Description </summary>
		/// <remarks> Database Path: WebbnessCMS.Security_EntityMenuTypes.EntityMenuTypeID.</remarks>
		/// <value> System.Int32. </value>
			public System.Int32? EntityMenuTypeID
		{
    		get {return _entitymenutypeid;}
				set {_entitymenutypeid = value;}
			}

		private System.Int32? _entitymenutypeid;
		
							/// <summary>
		/// Property Name - No Description </summary>
		/// <remarks> Database Path: WebbnessCMS.Security_EntityMenuTypes.Name.</remarks>
		/// <value> System.String. </value>
			[ValidateNonEmpty("Name is a required field.")]
			public System.String Name
		{
    		get {return _name;}
	    		set {_name = value;}
			}

		private System.String _name;
		
							/// <summary>
		/// Property Controller - No Description </summary>
		/// <remarks> Database Path: WebbnessCMS.Security_EntityMenuTypes.Controller.</remarks>
		/// <value> System.String. </value>
			public System.String Controller
		{
    		get {return _controller;}
	    		set {_controller = value;}
			}

		private System.String _controller;
		
							/// <summary>
		/// Property ShowInMenu - No Description </summary>
		/// <remarks> Database Path: WebbnessCMS.Security_EntityMenuTypes.ShowInMenu.</remarks>
		/// <value> System.Boolean. </value>
			[ValidateNonEmpty("Show In Menu is a required field.")]
			public System.Boolean? ShowInMenu
		{
    		get {return _showinmenu;}
	    		set {_showinmenu = value;}
			}

		private System.Boolean? _showinmenu;
		
			
	
		/// <summary>
		/// Binds the surrogate values to the search template.
		/// </summary>
		/// <param name="emptyTemplate">The empty template.</param>
		public void BindToSearchTemplate(EntityMenuTypeTemplate emptyTemplate)
		{
			}

	}
	#endregion

}

